package com.example.cqcet_demo.fragment;

import android.support.v4.app.Fragment;

/**
 * Created by Mr.z on 2017/6/19.
 */

public abstract class BaseFragment extends Fragment {

    /** Fragment当前状态是否可见 */
    protected boolean isVisible;


    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);

        if(getUserVisibleHint() && isVisible) {
            lazyLoad();
        } else {
            isVisible = false;
        }
    }


    /**
     * 可见
     */
    protected void onVisible() {
        lazyLoad();
    }

    /**
     * 延迟加载
     * 子类必须重写此方法
     */
    protected abstract void lazyLoad();
}
